home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / infosearch.idb / usr / lib / infosearch / bin / sgindexAdmin_l10n.z / sgindexAdmin_l10n
Text File  |  2002-10-15  |  6KB  |  284 lines

  1. #!/usr/bin/perl
  2. #
  3. # Copyright 1996-2002, Silicon Graphics, Inc.
  4. # All Rights Reserved.
  5. #
  6. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  7. # the contents of this file may not be disclosed to third parties, copied or
  8. # duplicated in any form, in whole or in part, without the prior written
  9. # permission of Silicon Graphics, Inc.
  10. #
  11. # RESTRICTED RIGHTS LEGEND:
  12. # Use, duplication or disclosure by the Government is subject to restrictions
  13. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  14. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  15. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  16. # rights reserved under the Copyright Laws of the United States.
  17. #
  18. # requires perl5
  19. #
  20. # -----------------
  21. # sgindexAdmin_l10n
  22. # -----------------
  23. #
  24. # Create localized content databases.
  25. #
  26.  
  27. require 5;
  28.  
  29. #----------------------------
  30. # initialize global variables
  31. #
  32. umask 022;
  33. %dbList   = ();
  34. $_db      = '';
  35. $toolroot = $ENV{'TOOLROOT'};
  36. $root     = '';                 # root for database path, not tools
  37. $verbose  = 0;
  38.  
  39. #----------------------
  40. # examine cmd line args
  41. #
  42. while($arg = shift(@ARGV)){
  43.  
  44.     if ($arg eq "-v") {
  45.         $verbose = 1;
  46.     } elsif ($arg eq "-r") {
  47.         $root = shift(@ARGV);
  48.     } elsif ($arg =~ /\-h/) {
  49.         &usage();
  50.     } else {
  51.         $_db = $arg;
  52.     }
  53. }
  54.  
  55. &readInfosrchCfg();
  56. &updateIndex($_db);
  57. exit(0);
  58.  
  59.  
  60. #------
  61. # usage
  62. #
  63. sub usage {
  64.     print "\nUsage:\n\tsgindexAdmin_l10n [ <database> ]\n";
  65.     exit(1);
  66. }
  67.  
  68.  
  69. #----------------
  70. # readInfosrchCfg
  71. #
  72. sub readInfosrchCfg {
  73.  
  74.   my($cfg) = "${toolroot}/usr/lib/infosearch/C/infosrch.cfg";
  75.   open(CFG, "$cfg") or return;
  76.  
  77.   my($db, $db_pth, $db_srch, $db_eng) = '';
  78.  
  79.   while (<CFG>) {
  80.  
  81.     if (/\<DATABASE(.*)\>/) {
  82.  
  83.       ($db, $db_pth, $db_srch, $db_eng) = '';
  84.       $db      = $1 if (/ID\s*=\s*"([^"]+)"/);
  85.       $db_pth  = $1 if (/PATH\s*=\s*"([^"]+)"/);
  86.       $db_srch = $1 if (/SRCH\s*=\s*"([^"]+)"/);
  87.       $db_eng  = $1 if (/SE\s*=\s*"([^"]+)"/);
  88.  
  89.       if ($db_srch =~ /alt/) {
  90.           $dbList{$db} = { 'pth' => "${root}${db_pth}",
  91.                            'eng' => "${db_eng}"  };
  92.       }
  93.     }
  94.   }
  95.   close(CFG);
  96. }
  97.  
  98.  
  99. #-------------------------------------
  100. # updateIndex($db) # All if $db = NULL
  101. #
  102. sub updateIndex {
  103.  
  104.   my($arg) = @_;
  105.   my($db) = '';
  106.  
  107.   if ($arg eq '') {
  108.       foreach $db (keys %dbList) {
  109.          &updateDB($db);
  110.       }
  111.   } else {
  112.       &updateDB($arg);
  113.   }
  114. }
  115.  
  116.  
  117. #--------------
  118. # updateDB($db)
  119. #
  120. sub updateDB {
  121.  
  122.   my($db) = @_;
  123.   my($db_pth, $db_eng) = '';
  124.  
  125.   if ($db eq '' || ($db_pth = $dbList{$db}->{'pth'}) eq '') {
  126.       if($verbose == 1) {
  127.          print "sgindexAdmin_l10n: Cannot access database ($db)\n";
  128.       }
  129.       return;
  130.   }
  131.  
  132.   # check to see if area exists, etc.
  133.   #
  134.   if (!(-d $db_pth)) {
  135.         if($verbose == 1) {
  136.            print "sgindexAdmin_l10n: Cannot access $db_pth ($db)\n";
  137.         }
  138.         return;
  139.   }
  140.   if (!(-w $db_pth)) {
  141.         if($verbose == 1) {
  142.            print "sgindexAdmin_l10n: Cannot write to $db_pth ($db)\n";
  143.         }
  144.         return;
  145.   }
  146.  
  147.   # create index area
  148.   #
  149.   if (!(-d "${db_pth}/SGIindex")) {
  150.       mkdir("${db_pth}/SGIindex", 0755) || do {
  151.        if($verbose == 1) {
  152.            print "sgindexAdmin_l10n: Cannot create ${db_pth}/SGIindex ($db)\n";
  153.        }
  154.        return;
  155.       };
  156.   }
  157.  
  158.   # clean out
  159.   #
  160.   system("rm -f ${db_pth}/SGIindex/*");
  161.  
  162.  
  163.   # create database
  164.   #
  165.   if (($db_eng = $dbList{$db}->{'eng'}) =~ /namazu/i) {
  166.       
  167.       &use_namazu($db, $db_pth);
  168.  
  169.   } else {
  170.  
  171.       # use std infosearch stuff
  172.       #
  173.       $cmd = "${toolroot}/usr/lib/infosearch/bin/booksAdmin -force ${db_pth}";
  174.       system($cmd);
  175.       die "sgindexAdmin_l10n: booksAdmin failed ($db): $!\n" if ($?);
  176.  
  177.       $cmd ="(mv -f ${db_pth}/SGIindex/bks.dct ${db_pth}/SGIindex/${db}.dct;" .
  178.              "mv -f ${db_pth}/SGIindex/bks.idx ${db_pth}/SGIindex/${db}.idx;" .
  179.              "mv -f ${db_pth}/SGIindex/bks.inv ${db_pth}/SGIindex/${db}.inv;" .
  180.              "mv -f ${db_pth}/SGIindex/bks.ttl ${db_pth}/SGIindex/${db}.ttl)";
  181.       system($cmd);
  182.       die "sgindexAdmin_l10n: Command failed (mv) ($db): $!\n" if ($?);
  183.   }
  184. }
  185.  
  186.  
  187.  
  188. #-------------------------
  189. # use_namazu($db, $db_pth)
  190. #
  191. sub use_namazu {
  192.  
  193.   my($db, $db_pth) = @_;
  194.  
  195.   if ($db eq '' || $db_pth eq '' || $dbList{$db}->{'eng'} !~ /namazu/i) {
  196.       if ($verbose == 1) {
  197.          print "sgindexAdmin_l10n: Wrong indexing engine ($db)\n";
  198.       }
  199.       return;
  200.   }
  201.  
  202.  
  203.   # get a set of bookshelves
  204.   #
  205.   my($d, $la, $cmd) = '';
  206.   my(@dirs) = ();
  207.   open(FP, "ls -1 ${db_pth}/*/booklist.txt |") || do {
  208.       if ($verbose == 1) {
  209.          print "sgindexAdmin_l10n: Command failed (ls) ($db)\n";
  210.       }
  211.       return;
  212.   };
  213.  
  214.   while(<FP>) {
  215.      chop;
  216.      $_ =~ s/\/booklist.txt$//;
  217.      push(@dirs, $_);
  218.   }
  219.   close(FP);
  220.  
  221.   if ((@dirs+0) == 0) {
  222.       if ($verbose == 1) {
  223.          print "sgindexAdmin_l10n: Nothing to index ($db)\n";
  224.       }
  225.       return;
  226.   }
  227.  
  228.  
  229.   # create list of files to index
  230.   #
  231.   open(FD, "> ${db_pth}/SGIindex/flist.txt") || do {
  232.       if ($verbose == 1) {
  233.          print "sgindexAdmin_l10n: Cannot create file list ($db)\n";
  234.       }
  235.       return;
  236.   };
  237.  
  238.   foreach $d (@dirs) {
  239.  
  240.       if (!(-d $d)) {
  241.           next;
  242.       }
  243.  
  244.       open (FP, "/sbin/find $d -name '*.html' -print |") || do {
  245.           if ($verbose == 1) {
  246.               print "sgindexAdmin_l10n: Command failed (find) ($db)\n";
  247.           }
  248.           return;
  249.       };
  250.       while(<FP>) {
  251.         if( $_ =~ /\/lo[etpf]+\.html/ ) {
  252.             next;
  253.         }
  254.         print FD $_;
  255.       }
  256.       close(FP);
  257.   }
  258.   close(FD);
  259.  
  260.   
  261.   # perform the indexing
  262.   #
  263.   ($la) = ($db_pth =~ m#\/(.*?)_bookshelves#is);
  264.   if ($la =~ /^ja/i) {
  265.       $la = 'eucJP';
  266.   }
  267.  
  268.   $cmd = "${toolroot}/usr/lib/infosearch/bin/mknmz " .
  269.          "-F ${db_pth}/SGIindex/flist.txt " .
  270.          "-O ${db_pth}/SGIindex --indexing-lang=${la} " .
  271.          "--replace='s#/${db_pth}/##'";
  272.   system($cmd);
  273.   die "sgindexAdmin_l10n: mknmz failed ($db): $!\n" if ($?);
  274.  
  275.   $cmd = "cp -f ${toolroot}/usr/lib/infosearch/l10n/namazu/template/NMZ.result.sgi " .
  276.          "${db_pth}/SGIindex";
  277.   system($cmd);
  278.  
  279.   unlink("${db_pth}/SGIindex/flist.txt");
  280.   return;
  281. }
  282.  
  283.  
  284.